home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / gpen32k / source / src / gpen32ks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  8.7 KB  |  413 lines

  1. /*****************************************************************
  2.  
  3.         G-Pen32k専用部
  4.                             Copyright(C) 1991-1994 OKOME
  5. *****************************************************************/
  6.  
  7. #include    <stdio.h>
  8. #include    <stdlib.h>
  9. #include    <string.h>
  10. #include    <EGB.h>
  11. #include    <MOS.h>
  12. #include    <Normlib.h>
  13. #include    <okome.h>
  14. #include    <GPen32k.h>
  15. #include    <GPenSub.c>
  16.  
  17. void colmix(int mb, int s)    /*    色混ぜ屋    */
  18. {
  19.     int i, b, r, g, b1,r1,g1, b2,r2,g2 ;
  20.     char wm[CBX4*2];
  21.     s+=4;
  22.     if (s==4 || s==5)
  23.         mcl[s] = mcl[mb];
  24.  
  25.     b1 =   mcl[4]         & 0x1f ;
  26.     r1 = ( mcl[4] >>  5 ) & 0x1f ;
  27.     g1 = ( mcl[4] >> 10 ) & 0x1f ;
  28.     b2 =   mcl[5]         & 0x1f ;
  29.     r2 = ( mcl[5] >>  5 ) & 0x1f ;
  30.     g2 = ( mcl[5] >> 10 ) & 0x1f ;
  31.  
  32.     for (i = 0; i<CBX4; i++)
  33.     {
  34.         b = b1 + i * ( b2-b1 + sign( b2-b1 ) ) /CBX4 ;
  35.         r = r1 + i * ( r2-r1 + sign( r2-r1 ) ) /CBX4 ;
  36.         g = g1 + i * ( g2-g1 + sign( g2-g1 ) ) /CBX4 ;
  37.         WORD(wm+i*2)=(g << 10) + (r << 5) + b;
  38.     }
  39.     egbputZ(CBX1,CBY1,CBX2,CBY2,CBX4,1,wm);
  40.     boxf( CBLX1,CBLY1,CBLX2,CBLY2, mcl[4] );
  41.     boxf( CBRX1,CBRY1,CBRX2,CBRY2, mcl[5] );
  42. }
  43.  
  44. void wsize( int mb, int s )
  45. {
  46.     static int k=3;
  47.     const int h = 2;
  48.     int mx, my;
  49.     wget();
  50.     wpg(0);
  51.     boxf( (NX1-h)*bi-1, (NY1-h)*bi-1, (NX2+h+1)*bi, (NY2+h+1)*bi, BCL );
  52.     wkugiri(0);
  53.     nx[k] = NX1;
  54.     ny[k] = NY1;
  55.     if (mb & 1)
  56.         k = (k+1) % (5+s);
  57.     else {
  58.         if (--k<0)    k = 4+s;
  59.     }
  60.     wb = wallbl[k];
  61.     NX4 = (8/bi) << k;
  62.     NY4 = NX4;
  63.     NX1 = nx[k];
  64.     NY1 = ny[k];
  65.     wpg(1);
  66.     wput();
  67.     wpg(0);
  68.     if (NX4<WX4)    wkugiri(1);
  69.     biboxbf( NX1, NY1, NX2, NY2, 0, 4, 4 );
  70.     wpg(1);
  71.     mbout(&mb, &mx, &my);
  72. }
  73.  
  74. static int HSV_h, HSV_s, HSV_v;
  75. static hrs=0;
  76.  
  77. /*    HSVパレット    */
  78. void HSVcolms(int j)
  79. {
  80.     int c;
  81.     switch (j)
  82.     {
  83.     case 0:    c = HSV_h/6;    break;
  84.     case 1:    c = HSV_s;        break;
  85.     case 2:    c = HSV_v;        break;
  86.     } 
  87.     view(PALX*bi,PALY*bi,PALX*bi+255,479);
  88.     boxf( PALX*bi      , PALY*bi + j   *PALB*bi + 1,
  89.           PALX*bi + 255, PALY*bi +(j+1)*PALB*bi - 1, 0 );
  90.     line( PALX*bi + c+1, PALY*bi + j   *PALB*bi + 2,
  91.           PALX*bi + c+1, PALY*bi +(j+1)*PALB*bi - 1, 8);
  92.     line( PALX*bi + c, PALY*bi + j   *PALB*bi + 1,
  93.           PALX*bi + c, PALY*bi +(j+1)*PALB*bi - 2, 15);
  94.     view(0,0,639,479);
  95. }
  96.  
  97. void HSVcolp(int h, int s, int v)        /*    HSV表示    */
  98. {
  99.     int i;
  100.     char wm[1024];
  101.     mcl[0] = (mcl[0] & 0x8000) | HSVto32k(h,s,v);
  102.     mbclp();
  103.     for (i=0; i<128; i++) {
  104.         WORD(wm    +i*2)=HSVto32k(i*12,s,v);
  105.         WORD(wm+256+i*2)=HSVto32k(h,i*2,v);
  106.         WORD(wm+512+i*2)=HSVto32k(h,s,i*2);
  107.     }
  108.     egbputZ(PALX,PALY, PALX+127,PALY+PALB*3-1, 128,3, wm);
  109.     wpg(0);
  110.     for (i=0; i<3; i++)
  111.         HSVcolms(i);
  112.     wpg(1);
  113. }
  114.  
  115. void HSVmc(int mb, int mx, int my)
  116. {
  117.     int y, c;
  118.     y = ( my - PALY*bi ) / ( PALB*bi );
  119.     umosv(PALX, PALY+PALB*y, PALX+127, PALY+PALB*(y+1)-1 );
  120.     while (mb!=0)
  121.     {
  122.         MOS_rdpos( &mb, &mx, &my );
  123.         c = mx - PALX*bi;
  124.         switch(y)
  125.         {
  126.         case 0:    HSV_h = c*6;    break;
  127.         case 1: HSV_s = c;    break;
  128.         case 2: HSV_v = c;    break;
  129.         }
  130.         HSVcolp(HSV_h,HSV_s,HSV_v);
  131.     }
  132.     mosv(0, 0, 639, 479);
  133. }
  134.  
  135. /*    カラー選択パレット    */
  136. void mcolms( int j )        /*    カラーバー  □表示    */
  137. {
  138.     int c, k;
  139.     if (hrs!=0)
  140.         HSVcolms(j);
  141.     else {
  142.         k = ( j + 1 ) % 3 ;
  143.         c = ( mcl[0] / (1 << (k*5))) & 0x1f;
  144.         boxf( PALX*bi + 1  , PALY*bi + j   *PALB*bi + 1,
  145.               PALX*bi + 255, PALY*bi +(j+1)*PALB*bi - 1, 0 );
  146.         boxb( PALX*bi + c * 8 + 2, PALY*bi + j   *PALB*bi + 2,
  147.               PALX*bi + c * 8 + 7, PALY*bi +(j+1)*PALB*bi - 1, 8 );
  148.         boxb( PALX*bi + c * 8 + 1, PALY*bi + j   *PALB*bi + 1,
  149.               PALX*bi + c * 8 + 6, PALY*bi +(j+1)*PALB*bi - 2, 15 );
  150.     }
  151. }
  152.  
  153. void mcols( int c )            /*    カラーバー表示    */
  154. {
  155.     int i, j;
  156.     char wm[128];
  157.     if (hrs!=0 && c != mcl[0]) {
  158.         c32toHSV(c, &HSV_h,&HSV_s,&HSV_v);
  159.         HSVcolp(HSV_h,HSV_s,HSV_v);
  160.     } else {
  161.         if ( c != mcl[0] ) {
  162.             mcl[0] = c;
  163.             mbclp();
  164.             for ( c = 0; c <= 2; c++ ) {
  165.                 j = (( c + 1 ) % 3) * 5 ;
  166.                 for ( i = 0; i<32; i++)
  167.                     WORD(wm+i*2) = (i<<j) + (mcl[0] & (0x7fff - (0x1f<<j)));
  168.                 egbputZ(PALX    , PALY+(c+1)*PALB-2,
  169.                         PALX+127, PALY+(c+1)*PALB-1, 32, 1, wm);
  170.             }
  171.             wpg(0);
  172.             for ( j=0; j<=2; j++)
  173.                 mcolms(j);
  174.             wpg(1);
  175.         }
  176.     }
  177. }
  178.  
  179. void mcolm( int mb, int mx, int my )        /*    RGB カラー選択バー    */
  180. {
  181.     int i, y, c;
  182.     if (hrs!=0)
  183.         HSVmc(mb, mx, my);
  184.     else {
  185.         y = ( my - PALY*bi ) / ( PALB*bi );
  186.         i = ( 1 << (((y + 1) % 3) * 5) );
  187.         umosv(PALX, PALY+PALB*y, PALX+127, PALY+PALB*(y+1)-1 );
  188.         while (mb!=0) {
  189.             MOS_rdpos( &mb, &mx, &my );
  190.             c = (mx - PALX*bi) / 8;
  191.             mcols((mcl[0] & (0xffff - 0x1f * i)) + c * i);
  192.         }
  193.         mosv(0, 0, 639, 479);
  194.     }
  195. }
  196.  
  197. void hsrg(int i)
  198. {
  199.     int x, y;
  200.     char wm[64];
  201.     if (i!=-1) {
  202.         if (i==0 || i==1)
  203.             hrs=i;
  204.         else
  205.             hrs = 1-hrs;
  206.     }
  207.     wpg(0);
  208.     biubox( PALX-12, PALY, PALX-4, PALY+PALB*3-1, 8, 15, 0 );
  209.     if (hrs==0) {
  210.         font12((PALX-11)*bi,PALY*bi+12,"R",15);
  211.         font12((PALX-11)*bi,PALY*bi+26,"G",15);
  212.         font12((PALX-11)*bi,PALY*bi+40,"B",15);
  213.         wpg(1);
  214.         for ( y = 0; y <= 2; y++ ) {
  215.             i = ( y + 1 ) % 3 ;
  216.             for ( x = 0; x < 32; x++ )
  217.                 WORD(wm+x*2) = x * (1 << (i * 5));
  218.             egbputZ(PALX, PALY+y*PALB, PALX+127, PALY+(y+1)*PALB-1, 32, 1, wm);
  219.         }
  220.     } else {
  221.         font12((PALX-11)*bi,PALY*bi+12,"H",15);
  222.         font12((PALX-11)*bi,PALY*bi+26,"S",15);
  223.         font12((PALX-11)*bi,PALY*bi+40,"V",15);
  224.         wpg(1);
  225.     }
  226.     i = mcl[0];
  227.     mcl[0] ^= 1;
  228.     mcols(i);
  229.     mbout(&i,&x,&y);
  230. }
  231.  
  232. void svpp(int mx)
  233. {
  234.     char a[32];
  235.     int mb, my;
  236.     mosv(VX1,VY1,VX2,VY2);
  237.     do {
  238.         my = mx - VX1;
  239.         if (my!=vr) {
  240.             vr = my;
  241.             wpg(0);
  242.             boxf(VX1,VY1,VX2,VY2,8);
  243.             line(VX1+vr,VY1,VX1+vr,VY2,15);
  244.             uboxf(VX2+16,VY1-4,VX2+48,VY2+4,8,15,8);
  245.             _itoa(vr,a,10);
  246.             font8(VX2+42-8*strlen(a),VY2+3,a,15);
  247.             wpg(1);
  248.         }
  249.         MOS_rdpos(&mb,&mx,&my);
  250.     }    while (mb);
  251.     mosv(0,0,639,479);
  252. }
  253.  
  254. void ptnsave4pg( char *name, int sx, int sy )
  255. {
  256.     int x, y, p;
  257.     FILE *fp;
  258.     if ((fp = fopen( name, "wb")) == NULL )
  259.         return;
  260.     for (p=0; p<=3; p++ ) {
  261.         for ( y=0; y<BY4/sy; y++ ) {
  262.             for ( x=0; x<BX4/sx; x++ ) {
  263.                 egbget(BX1+x*sx,BY1+y*sy,BX1+sx-1+x*sx,BY1+sy-1+y*sy,b);
  264.                 fwrite(b, 1, sx*sy*2, fp);
  265.             }
  266.         }
  267.         page(1);
  268.     }
  269.     page(-4);
  270.     fclose(fp);
  271. }
  272.  
  273. void ptnload4pg( char *name, int sx, int sy )
  274. {
  275.     int x, y, p;
  276.     FILE *fp;
  277.     if ((fp = fopen( name, "rb")) == NULL )
  278.         return;
  279.     for ( p=0; p<=3; p++ ) {
  280.         for ( y=0; y<BY4/sy; y++ ) {
  281.             for ( x=0; x<BX4/sx; x++ ) {
  282.                 if (fread(b, 1, sx*sy*2, fp))
  283.                     vput2(BX1+x*sx,BY1+y*sy,BX1+sx-1+x*sx,BY1+sy-1+y*sy,b);
  284.             }
  285.         }
  286.         page(1);
  287.     }
  288.     page(-4);
  289.     fclose(fp);
  290. }
  291.  
  292. void rchc( void )
  293. {
  294.     int mb, mx, my;
  295.     mcl[0]^= 0x8000;
  296.     mbclp();
  297.     mbout( &mb, &mx, &my );
  298. }
  299.  
  300. int ptr16dsa(char *name)
  301. {
  302.     char cl[64];
  303.     int i, j, x, y, cf, ca;
  304.     FILE *fp;
  305.     if ((fp = fopen( name, "wb")) == NULL )
  306.         return (1);
  307.     for (y=0; y<BY4/16; y++) {
  308.         for (x=0; x<BX4/16; x++) {
  309.             cf = 0;
  310.             WORD(cl) = 0;
  311.             egbget(BX1+x*16, BY1+y*16, BX1+15+x*16, BY1+15+y*16, b);
  312.             EGB_writePage(work,0);
  313.             view(0,0,1023,511);
  314.             for (i=0; i<256; i++) {
  315.                 ca = 16;
  316.                 if (WORD(b+i*2) & 0x8000)
  317.                     ca = 0;
  318.                 else {
  319.                     for (j=1; j<=cf; j++) {
  320.                         if (WORD(cl+j*2)==WORD(b+i*2)) {
  321.                             ca = j;
  322.                             break;
  323.                         }
  324.                     }
  325.                     if (ca==16) {
  326.                         if (cf==15) {
  327.                             message2(1,"色数が16色を超えています",1);
  328.                             break;
  329.                         } else {
  330.                             ++cf;
  331.                             WORD(cl+cf*2) = WORD(b+i*2);
  332.                             ca = cf;
  333.                         }
  334.                     }
  335.                 }
  336.                 line(i,511,i,511,ca);
  337.             }
  338.             egbget(0,511,255,511,b);
  339.             EGB_writePage(work,1);
  340.             fwrite(cl,1,32,fp);
  341.             fwrite(b,1,128,fp);
  342.         }
  343.     }
  344.     fclose(fp);
  345.     return (0);
  346. }
  347.  
  348. int ptr16dlo(char *name)
  349. {
  350.     char cl[64];
  351.     unsigned char *p;
  352.     int i, x, y;
  353.     FILE *fp;
  354.     p = (unsigned char *)b+512;
  355.     if ((fp = fopen( name, "rb")) == NULL )
  356.         return (1);
  357.     for (y=0; y<BY4/16; y++) {
  358.         for (x=0; x<BX4/16; x++) {
  359.             fread(cl,1,32,fp);
  360.             fread(p,1,128,fp);
  361.             WORD(cl) = 0x8000;
  362.             for (i=0; i<256; i++)
  363.                 WORD(b+i*2) = WORD(cl+(((p[i/2] >> ((i&1)*4)) & 0xf)*2));
  364.             egbput(BX1+x*16, BY1+y*16, BX1+15+x*16, BY1+15+y*16, b);
  365.         }
  366.     }
  367.     fclose(fp);
  368.     return(0);
  369. }
  370.  
  371. int cdasave(char *nn)
  372. {
  373.     char l[256], s[256];
  374.     char *p;
  375.     unsigned short int b[256];
  376.     int i, j, x, y;
  377.     FILE *fp;
  378.     if (( fp = fopen( nn, "wt" ) )==NULL)
  379.         return (1);
  380.     fputs("short int chr[] = {",fp);
  381.     for (i = 0; i < 64; i++) {
  382.         x = i % 8;
  383.         y = (i / 8) % 8;
  384.         egbget(BX1+x*16,BY1+y*16, BX1+x*16+15,BY1+y*16+15, (char *)b);
  385.         fputs("\n\t/* No.",fp);
  386.         fputs(_itoa(i,l,16),fp);
  387.         fputs( " */", fp );
  388.         for (j = 0; j<256; j++)    {
  389.             if (j % 8 == 0)
  390.                 fputs( "\n\t0x", fp );
  391.             else
  392.                 fputs( ", 0x", fp );
  393.             strcpy( s, "000" );
  394.             strcat( s, _itoa( b[j], l, 16 ) );
  395.             p = s + strlen(s) - 4;
  396.             fputs( p, fp );
  397.             if (j % 8 == 7 && (i<63 || j!=255))
  398.                 fputs( ",", fp );
  399.         }
  400.     }
  401.     fputs( "\n\t}\n", fp );
  402.     fclose(fp);
  403.     return (0);
  404. }
  405.  
  406. /*
  407. int cdaload()
  408.  
  409. int basdasa()
  410.  
  411. int basdalo()
  412. */
  413.